package com.jingdun.sport.api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingdun.sport.bean.model.ApiResult;
import com.jingdun.sport.bean.model.Prizes;
import com.jingdun.sport.service.PrizesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/sport/prizes/")
@Api(tags = "奖品接口")
public class PrizeController {

    @Autowired
    private PrizesService prizesService;

    /**
     * 新建奖品接口
     */
    @PostMapping("/addPrize")
    @ApiOperation(value = "新建奖品接口", notes = "新建奖品接口")
    public ResponseEntity<ApiResult> addPrize(@RequestBody Prizes prize) {
        prizesService.addPrize(prize);
        ApiResult apiResult = new ApiResult();
        //return ResponseEntity.ok().build();
        return ResponseEntity.ok(apiResult);
    }

    /**
     * 获取奖品详情接口
     */
    @GetMapping("/getPrizeDetail")
    @ApiOperation(value = "获取奖品详情接口", notes = "获取奖品详情接口")
    public ApiResult getPrizeDetail(long id){
        Map m = new HashMap<String, Object>();
        m.put("id", id);
        Prizes prize = prizesService.getPrizeDetail(m);
        ApiResult apiResult = new ApiResult();
        apiResult.setData(prize);
        return apiResult;
    }

    /**
     * 删除奖品接口
     */
    @PostMapping("/removePrize")
    @ApiOperation(value = "删除奖品接口", notes = "删除奖品接口")
    public ResponseEntity removePrize(long id){
        Prizes prize = new Prizes();
        prize.setId(id);
        prize.setEnabled("0");
        prizesService.updatePrize(prize);
        ApiResult apiResult = new ApiResult();
        //return ResponseEntity.ok().build();
        return ResponseEntity.ok(apiResult);
    }

    /**
     * 修改奖品接口
     */
    @PostMapping("/updatePrize")
    @ApiOperation(value = "修改奖品接口", notes = "修改奖品接口")
    public ResponseEntity updatePrize(@RequestBody Prizes prize){
        prizesService.updatePrize(prize);
        ApiResult apiResult = new ApiResult();
        //return ResponseEntity.ok().build();
        return ResponseEntity.ok(apiResult);
    }
    
	/**
     * 分页获取奖品接口
     */
    @RequestMapping("/getPaginationPrizes")
    @ApiOperation(value = "分页获取奖品接口", notes = "分页获取奖品接口")
    public ResponseEntity <ApiResult> getPaginationPrizes(long size, long current) {
        Map m = new HashMap<String, Object>();
        m.put("size", size);
        m.put("current", current);
        Page<Map<String, Object>> page = prizesService.getPaginationPrizes(m);
        ApiResult apiResult = new ApiResult();
        apiResult.setData(page);
        return ResponseEntity.ok(apiResult);
    }

}